//auto_ptr is a template class
//an 'auto_ptr' is initialized by a pointer
//can be deferenced in the way a pointer can


#include <iostream>
#include <memory>
using namespace std;

class A {
public:
  int i;
  A(){i = 12;cout<<"A::A()"<<endl;}
  ~A(){cout<<"~A::A()"<<endl;}
  //error: constructors and destructors may not be cv-quilified
};

int main()
{
  A* a_ptr = new A;
  cout<<"a_ptr->i\t"<<a_ptr->i<<endl;
  cout<<"---------"<<endl;
 //  const
  auto_ptr<A> a_auto_ptr(a_ptr);
  cout<<"a_ptr->i\t"<<a_ptr->i<<endl;
  cout<<"a_auto_ptr->i\t"<<a_auto_ptr->i<<endl;
  cout<<"---------"<<endl;
  auto_ptr<A> bptr(a_auto_ptr);
  //1. a const auto_ptr cannot be copied.
  cout<<"a_ptr->i\t"<<a_ptr->i<<endl;
  cout<<"a_auto_ptr\t"<<a_auto_ptr.get()<<endl;
  //2. destructive copy semantics
  //2. when on auto_ptr is copied into another,
  //2. the source no longer points to anything.
  cout<<"bptr->i\t\t"<<bptr->i<<endl;
  return 0;
//0. The object pointed to will be implicitly deleted at the end of the auto_ptr'scope
}
